package com.example.yyang.demo.fragment


import android.os.Bundle
import android.support.v4.app.Fragment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast

import com.example.yyang.demo.R
import com.example.yyang.demo.model.Repo
import com.example.yyang.demo.network.ApiClient
import com.example.yyang.demo.network.ApiErrorModel
import com.example.yyang.demo.network.ApiResponse
import com.example.yyang.demo.network.NetworkScheduler

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 *
 */
class FindFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_find, container, false)
    }
    override fun onResume() {
        super.onResume()
        ApiClient.instance.service.listRepos("ZYRzyr")
                .compose(NetworkScheduler.compose())
                .subscribe(object : ApiResponse<List<Repo>>(this!!.getContext()!!) {
                    override fun success(data: List<Repo>) {
                        Log.e("result",data.toString())
                    }

                    override fun failure(statusCode: Int, apiErrorModel: ApiErrorModel) {
                        Toast.makeText(activity, apiErrorModel.message, Toast.LENGTH_SHORT).show()
                    }
                })
    }

}
